#include <func.h>

void* add(void* n)
{
    long long sum = 0;
    long long a = (long long) n;
    for(long long i = abs(a);i>=0;i--)
        sum += a++;

    pthread_exit((void*)sum);
}

int main(int argc,char* argv[])
{
    long long n;
    printf("Pleaes input a long long int:");
    scanf("%lld",&n);
    
    pthread_t tid1;
    int err1 = pthread_create(&tid1,NULL,add,(void*) (n/2));
    if(err1)
        error(1,err1,"pthread_create1");
    
    pthread_t tid2;
    int err2 = pthread_create(&tid2,NULL,add,(void*) (-n/2));
    if(err2)
        error(1,err2,"pthread_create2");
    
    sleep(1);
    
    long long sum1;
    long long sum2;

    pthread_join(tid1,(void**) &sum1);
    pthread_join(tid2,(void**) &sum2);

    printf("sum is : %lld\n",sum1 - sum2 - n/2);

    return 0;
}

